﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using HRM.DAL.DAO;
using HRM.DAL.Gateway;

namespace HRM.BLL
{
    public class PromotionManager
    {
        PromotionGateway gateway=new PromotionGateway();
        public bool SavePromotion(Promotion promotion)
        {
            try
            {
                DesignationManager designationManager = new DesignationManager();
                Designation designation = new Designation();
                designation.Title = promotion.PresentDesig;
                int presentDesigId = designationManager.GetDesignationId(designation);
                EmployeeManager employeeManager = new EmployeeManager();
                //Employee employee = new Employee();
                Code code = new Code();
                code.CodeName = promotion.Employee.EmpCode.CodeName;
                employeeManager.UpdateDesignation(code, presentDesigId);
                int empId = employeeManager.GetEmployeeID(code);
                return gateway.SavePromotion(empId,promotion);
            }
            catch (Exception)
            {
                throw new Exception("Please try agin , Error occured ! ");
            }
        }
        
        public List<Promotion> GetEmpPromotionHistory(Code code)
        {
             EmployeeManager employeeManager = new EmployeeManager();
             int empId = employeeManager.GetEmployeeID(code);
            return gateway.GetEmpPromotionHistory(empId);
        }

        public bool UpdatePromotion(Promotion promotion)
        {
            DesignationManager designationManager = new DesignationManager();
            Designation designation = new Designation();
            designation.Title = promotion.PresentDesig;
            int presentDesigId = designationManager.GetDesignationId(designation);
            EmployeeManager employeeManager = new EmployeeManager();
            //Employee employee = new Employee();
            Code code = new Code();
            code.CodeName = promotion.Employee.EmpCode.CodeName;
            employeeManager.UpdateDesignation(code, presentDesigId);
            int empId = employeeManager.GetEmployeeID(code);
            return gateway.UpdatePromotion(empId, promotion);
        }

    }
}